$(function(){
	$.post("selUserDoesExist",function(data){
		if(data.code==0){
			var rel=data.data
			$("input").each(function(){
				$(this).val(rel[$(this).attr("name")])
			})
		}
	})
	$("#tjxx").click(function(){
		var footballTeams=sessionStorage.getItem("hb_code")
		var votingType=getRequest('type')
		var name=$("input[name=name]").val()
		if(name==""){
			$.toast("姓名未填写", "cancel");
			return
		}
		var tel=$("input[name=tel]").val()
		if(tel==""){
			$.toast("手机号未填写", "cancel");
			return
		}
		if(checkPhone(tel)==false){
			$.toast("手机号不正确", "forbidden");
			return
		}
		var IDCard=$("input[name=IDCard]").val()
		if(IDCard==""){
			$.toast("身份证号未填写", "cancel");
			return
		}
		if(checkCode(IDCard)==false){
			$.toast("身份证号不正确", "forbidden");
			return
		}
		var address=$("input[name=address]").val()
		if(address==""){
			$.toast("请填写您的邮寄地址", "cancel");
			return
		}
		var senddata={}
		var url=''
		if(footballTeams==null||footballTeams==""||footballTeams==undefined){
			senddata={name,tel,IDCard,address}
			url='updateRegistrationInfo'
		}else{
			senddata={name,tel,IDCard,address,footballTeams,votingType}
			url='registAndVote'
		}
		$.showLoading('正在保存信息');
		$.post(url,senddata,function(data){
			if(data.code==0){
				 $.hideLoading();
				$.toast(data.msg,function(){
					sessionStorage.removeItem("hb_code")
					sessionStorage.setItem("hb_type",votingType)
					window.location.replace("wx_fx")
				})
			}else{
				 $.hideLoading();
				$.toast(data.msg, "forbidden");
			}
		})
	})
})
